<%@ Control Language="C#" Inherits="SoftwareMonkeys.Scriptech.Web.BaseScript" %>
<%@ Import namespace="SoftwareMonkeys.Scriptech.Configuration" %>
<%@ Import namespace="SoftwareMonkeys.Scriptech.Projects" %>
<%@ Import namespace="SoftwareMonkeys.Scriptech.Web" %>
<%@ Import namespace="SoftwareMonkeys.Scriptech.Business" %>
<%@ Import namespace="SoftwareMonkeys.Scriptech.Ftp" %>
<%@ Import namespace="System.IO" %>
<script runat="server">
public FtpServer CurrentFtpServer = null;

private void Page_Load(object sender, EventArgs e)
{
	Guid id = GetID();

	FtpServer ftpServer = RetrieveStrategy.New<FtpServer>().Retrieve<FtpServer>("ID", id);

	CurrentFtpServer = ftpServer;

	Name.Text = ftpServer.Name;
	Address.Text = ftpServer.Address;
	Username.Text = ftpServer.Username;
	Password.Text = ftpServer.Password;
	RemoteDirectory.Text = ftpServer.RemoteDirectory;

	DataBind();
}

private void UpdateButton_Click(object sender, EventArgs e)
{
	Guid id = GetID();

	FtpServer ftpServer = RetrieveStrategy.New<FtpServer>().Retrieve<FtpServer>("ID", id);

	ftpServer.Name = Name.Text;
	ftpServer.Address = Address.Text;
	ftpServer.Username = Username.Text;
	ftpServer.Password = Password.Text;
	ftpServer.RemoteDirectory = RemoteDirectory.Text;

	UpdateStrategy.New(ftpServer).Update(ftpServer);

	Response.Redirect(ScriptPath.GetUrl("FtpServerIndex.ascx"));

}

private Guid GetID()
{

	Guid id = Guid.Empty;

	if (Request.QueryString["FtpServerID"] != null && Request.QueryString["FtpServerID"] != String.Empty)
		id = new Guid(Request.QueryString["FtpServerID"]);

	if (id == Guid.Empty)
		Response.Redirect(ScriptPath.GetUrl("FtpServerIndex.ascx"));

	return id;
}
</script>
	<h1>Edit FTP Server</h1>
<hr/>
<div><a href='<%= Request.ApplicationPath %>'>Home</a> - <a href='<%= ScriptPath.GetUrl("FtpServers.ascx") %>'>FTP Servers</a></div>
<hr/>
	<table width="100%">
		<tr>
			<td>Name:</td>
			<td>
				<asp:textbox runat="server" id="Name" width="400px" text='<%# CurrentFtpServer.Name %>'/></td>
		</tr>
		<tr>
			<td>Address:</td>
			<td>
				<asp:textbox runat="server" id="Address" width="400px" text='<%# CurrentFtpServer.Address %>'/></td>
		</tr>
		<tr>
			<td>Username:</td>
			<td>
				<asp:textbox runat="server" id="Username" width="400px" text='<%# CurrentFtpServer.Username %>'/></td>
		</tr>
		<tr>
			<td>Password:</td>
			<td>
				<asp:textbox runat="server" id="Password" width="400px" text='<%# CurrentFtpServer.Password %>'/></td>
		</tr>
		<tr>
			<td>Remote directory:</td>
			<td>
				<asp:textbox runat="server" id="RemoteDirectory" width="400px" text='<%# CurrentFtpServer.RemoteDirectory %>'/></td>
		</tr>
		<tr>
			<td> </td>
			<td>
				<asp:button runat="server" id="UpdateButton" text="Update" onclick="UpdateButton_Click"/>
			</td>
		</tr>
	</table>